#ifndef CLIENT_H
#define CLIENT_H

#ifdef WIN32

#include <winsock2.h>

#elif defined (linux)

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h> /* close */
#include <netdb.h> /* gethostbyname */
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
typedef struct in_addr IN_ADDR;

#else

#error not defined for this platform

#endif

#define PORT_SERVEUR 22020
#define PORT_CLIENT	22120

#define BUF_SIZE 1024

#include <pthread.h>
#include "annuaire.h"

typedef enum {
	AFFICHER = 1,
	CHERCHER_SERVEUR = 2,
	DEMANDER_NUM = 3,
	AJOUTER = 4,
	SUPPRIMER = 5,
	IMPORTER = 6,
	EXPORTER = 7,
	QUITTER = 8
} Menu;

static annuaire annu = NULL;
char fichierAnnuaire[] = "annuaire.txt";
SOCKET sockServeur = -1;
int numClient = 0;

void init(void);
void end(void);
int connexionUDPServeur(const char *address, int port, SOCKADDR_IN *sin, int broadcast);
int connexionUDPServeurRecoit(int port);
int demanderAdresseServeur(char* adresseServeur);
int initConnexion(const char *address, int port);
int initConnexionServeur(int port);
void fermerConnexion(int sock);
int recevoirServeurTCP(SOCKET sock, char *buffer);
void envoyerServeurTCP(SOCKET sock, const char *buffer);
int recevoirUDP(SOCKET sock, SOCKADDR_IN *sin, char *buffer);
void envoyerUDP(SOCKET sock, SOCKADDR_IN *sin, const char *buffer);
int enregistrementAnnuaireServeur(SOCKET sockServeur);
int ajouterAnnuaireServeur(SOCKET sock, char *nom);
int demandeServeurIPClient(SOCKET sockServeur, char *nom, char *ipClient);
int demandeClientNumero(const char *adresseClient, const char *nomDemande, char *telAssocie);
int envoieClientNumero();

void clearScanf(void);
void menu(void);
void afficherMenu(void);
int actionsMenu(void);

#endif /* CLIENT_H */
